from typing import Any, Dict

from pydantic import Field

from core.agents.base import BaseAgent
from core.llm.factory import ModelType, create_llm_provider
from core.managers.eval_manager import EvalManager
from core.utils.log import mylogger


class EvalAgent(BaseAgent):

    model_type: ModelType = Field(
        default=ModelType.DOUBAO_SEED, description="LLM model type"
    )
    temperature: float = Field(default=0.1, description="Model temperature")
    output_dir: str = Field(default="data", description="Output directory")

    def model_post_init(self, __context: Any) -> None:
        """Initialize evaluation agent."""
        super().model_post_init(__context)
        self.llm = create_llm_provider(model_type=self.model_type)
        self.eval_manager = EvalManager(
            llm=self.llm, output_dir=self.output_dir, temperature=self.temperature
        )
        mylogger.info(f"EvalAgent initialized for {self.name}")

    async def process(self, input_data: Dict[str, Any]) -> str:
        character_file_path = input_data.get("character_file_path")
        result_file_path = input_data.get("result_file_path")
        scenario_file_path = input_data.get("scenario_file_path")

        if not all([character_file_path, result_file_path, scenario_file_path]):
            raise ValueError("Missing required file paths for evaluation")

        return await self.eval_manager.evaluate_dialogue(
            character_file_path=character_file_path,
            result_file_path=result_file_path,
            scenario_file_path=scenario_file_path,
        )
